<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>课程管理</title>
</head>
<link rel="stylesheet" href="__STATIC__/admin/js/layer/theme/default/layer.css">
<link rel="stylesheet" href="__STATIC__/admin/js/layui/css/layui.css">
<link rel="stylesheet" href="__STATIC__/admin/css/coursesCommon.css">
<link rel="stylesheet" href="__STATIC__/admin/js/jqzoom/jqzoom.css">
<link href="__STATIC__/admin/js/bootstrap/css/bootstrap.css"
      rel="stylesheet">
<link href="__STATIC__/admin/css/AdminLTE.css" rel="stylesheet"
      type="text/css" />
<body>
<button class="bt2 layui-btn layui-btn-normal">新增</button>
<table class="table table-hover">
    <tr class="tr_1">
        <th>ID</th>
        <th>课程名字</th>
        <th>课程标题</th>
        <th>上传者名字</th>
        <th>封面图片</th>
        <th>课程金额</th>
        <th>是否删除</th>
        <th>课程创建时间</th>
        <th>操作</th>
    </tr>
    {volist name="courses" id="v"}
    <tr>
        <td>{$v.courses_id}</td>
        <td>{$v.courses_name}</td>
        <td>{$v.courses_title}</td>
        <td>{$v.user_name}</td>
        <td class="zoomImg" >
            <img src="{$v.courses_photo}" width="150px" height="100px" alt="图片" jqimg='{$v.courses_photo}' >
        </td>
        <td>{$v.courses_money}</td>
        <td>{if condition="$v.courses_del eq '1'"}
            <span class='label label-danger wst-label'> 删除 </span>
            {elseif condition="$v.courses_del eq '2'" /}
            <span class='label label-danger wst-label'>待审核</span>
            {else/}
            <span class='label label-success wst-label'> 显示 </span>
            {/if}
        </td>
        <td>{$v.courses_time|date="Y-m-d H:i:s",###}</td>
        <td>
            {if condition="!$v.courses_del eq '2'" /}
                {if condition="$v.courses_del eq '1'"}
                <button class="bt1 btn btn-default glyphicon glyphicon-pencil" data-id="{$v.courses_id}" data-fid="1" >显示</button>
                {else /}
                <button class="bt1 btn btn-default glyphicon glyphicon-trash" data-id="{$v.courses_id}" data-fid="0">删除</button>
                {/if}

                <button class="bt3 btn btn-default glyphicon glyphicon-pencil" data-id="{$v.courses_id}">修改</button>
            {/if}
        </td>
    </tr>
    {/volist}
</table>
<script src="__STATIC__/admin/js/jquery.min.js"></script>
<script src="__STATIC__/admin/js/layer/layer.js"></script>
<script src="__STATIC__/admin/js/layui/layui.js"></script>
<script src="__STATIC__/admin/js/jqzoom/jqzoom.js"></script>


<script>


    //删除jquery
    $(document).ready(function(){
        $('.bt1').click(function () {
            if(!confirm("确定删除吗")){
                return false;
            }

            layer.load();
            setTimeout(function(){
                layer.closeAll('loading');
            }, 2000);

            var link = $(this);
            var courses = link.attr("data-id");
            var fid = link.attr("data-fid");

            $.get("{:url('admin/Courses/delete')}?id="+courses+"&fid="+fid,function (data) {

                if(data == 0){
                    layer.msg('删除状态修改成功', {icon: 1});

                    setTimeout(function(){
                        window.location.href = ("{:url('admin/courses/index')}");
                    }, 2000);

                }else {
                    layer.msg('删除状态修改失败', {icon: 2});
                }

            })

        })

        $(".bt3").click(function () {
            var link = $(this);
            var courses = link.attr("data-id");
            console.log(courses);

            $.get("{:url('admin/Courses/update')}?id="+courses,function (data) {
                var data = JSON.parse( data );

                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['420px', '300px'], //宽高
                    content: data+vdata()
                });

            })
        })

        //跳转新增jquery
        $('.bt2').click(function () {
            window.location.href = ("{:url('admin/courses/insert')}");
        })


    })

    function vdata() {
        var data ="<script>\n" +
            "        ///提交数据jquery\n" +
            "        $(document).ready(function(){\n" +
            "            $('.span').click(function () {\n" +
            "                if(!confirm(\"确定修改吗\")){\n" +
            "                    return false;\n" +
            "                }\n" +
            "                var data = {};\n" +
            "                data.courses_id = $(\".courses_id\").val();\n" +
            "                data.courses_name = $(\".courses_name\").val();\n" +
            "                data.courses_title = $(\".courses_title\").val();\n" +
            "                data.courses_money = $(\".courses_money\").val();\n" +
            "                console.dir(data);\n" +
            "                layer.load();\n" +
            "                setTimeout(function(){\n" +
            "                    layer.closeAll('loading');\n" +
            "                }, 2000);\n" +
            "                $.post(\"{:url('admin/Courses/cuorsesUpdate')}\",data,function (data) {\n" +
            "                    console.log(data);\n" +
            "                if(data == 1){\n" +
            "                    layer.msg('修改成功', {icon: 1,time: 2000});\n" +
            "                setTimeout(function(){\n" +
            "                    window.location.href = (\"{:url('admin/courses/index')}\");\n" +
            "                }, 2000);\n" +
            "                }else {\n" +
            "                    layer.msg('修改失败', {icon: 2});\n" +
            "                }\n" +
            "                })\n" +
            "            })\n" +
            "        })\n" +
            "<\/script>";
        return data;
    }


    layui.use(['laypage'], function() {
        var laypage = layui.laypage;
        //自定义首页、尾页、上一页、下一页文本
        laypage.render({
            elem: 'demo2'
            ,count: 10,
            limit: 3
            ,theme: '#1E9FFF'
        });

    })
</script>
</body>

</html>